<?php
/**
 * @author fyl
 * Date: 16-3-29 下午2:59
 */

class AdminService extends BaseService
{
    private static $self        =   NULL;

    private $mLogisticsLine      =  NULL;
    private $mForest             =  NULL;
    private $mVideo              =  NULL;
    private $mStorage            =  NULL;
    private $mHarbour            =  NULL;
    private $mHelpCenter         =  NULL;
    private $mInformation        =  NULL;
    private $mProduct            =  NULL;
    private $mProductArea        =  NULL;
    private $mProductBrand       =  NULL;
    private $mProductCate        =  NULL;
    private $mLevel              =  NULL;
    private $mSpec               =  NULL;
    private $mUser               =  NULL;
    private $mAdmin              =  NULL;
    private $mRole               =  NULL;
    private $mLog                =  NULL;
    private $mSupplier           =  NULL;
    private $mOrder              =  NULL;
    private $mForestNeed         = NULL;
    private $mHarbourNeed         =  NULL;
    private $mStorageNeed         =  NULL;
    private $mAds                =  NULL;
    private $mInquiry            =  NULL;
    private $mCustomize          =  NULL;
    private $mSupply             =  NULL;
    private $ProductPic          =  NULL;
    private $mPurchaseResource  = Null;
    private $mNewResource        = NULL;
    private $mInviteCode        = NULL;
    private $mOpinion = NULL;

    static public function instance()
    {
        if (self::$self == NULL) {
            self::$self = new self;
        }
        return self::$self;
    }


    public function __construct()
    {
        $this->mLogisticsLine       =   new Involved_LogisticsLineModel();
        $this->mForest              =   new Involved_ForestModel();
        $this->mVideo               =   new Involved_VideoModel();
        $this->mHarbour             =   new Involved_HarbourModel();
        $this->mStorage             =   new Involved_StorageModel();
        $this->mHelpCenter          =   new Involved_HelpCenterModel();
        $this->mInformation         =   new Involved_InformationModel();
        $this->mProduct             =   new Involved_ProductModel();
        $this->mProductArea         =   new Involved_ProducingAreaModel();
        $this->mProductBrand        =   new Involved_ProductBrandModel();
        $this->mProductCate         =   new Involved_ProductCateModel();
        $this->mSpec                =   new Involved_SpecModel();
        $this->mLevel               =   new Involved_LevelModel();
        $this->mUser                =   new Involved_UserModel();
        $this->mAdmin               =   new Involved_AdminModel();
        $this->mRole                =   new Involved_RoleModel();
        $this->mLog                 =   new Involved_LogModel();
        $this->mSupplier            =   new Involved_SupplierModel();
        $this->mOrder               =   new Involved_OrderModel();
        $this->mForestNeed          =   new Involved_ForestNeedModel();
        $this->mHarbourNeed         =   new Involved_HarbourNeedModel();
        $this->mStorageNeed         =   new Involved_StorageNeedModel();
        $this->mAds                 =   new Involved_AdsModel();
        $this->mInquiry             =   new Involved_InquiryModel();
        $this->mCustomize           =   new Involved_CustomizeModel();
        $this->mSupply              =   new Involved_SupplyModel();
        $this->mProductPic          =   new Involved_ProductPicModel();
        $this->mPurchaseResource    =   new Involved_PurchaseResourceModel();
        $this->mNewResource         =   new Involved_NewResourceModel();
        $this->mInviteCode          =   new Involved_InviteCodeModel();
        $this->mFeedback             = new Involved_FeedbackModel();
    }


    /**
     * 验证用户
     */
    public function LoginValidator($user)
    {
        #此处只做简单验证
        if(empty($user->username) || empty($user->password)){
            throw new Exception('必填项不能为空', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }
        if(strtolower($user->captcha) != strtolower(Session::get('mt_Captcha'))){
            throw new Exception('验证码错误', ProfessionErrorCodeEnum::ERROR_VERIFICATION_CODE_WRONG);
        }

        #数据验证
        $admin_info = $this->mAdmin->getLoginAdminInfo($user->username,md5($user->password));
        if(!$admin_info){
            throw new Exception('密码错误', ProfessionErrorCodeEnum::ERROR_PASSWORD_WRONG);
        }
        #存储SESSION
        Session::put(UserEnum::ADMIN_USER_KEY_ID, $admin_info->id);
        Session::put(UserEnum::ADMIN_USER_KEY, $admin_info);
        return $admin_info;
    }


    /**
     * 物流列表展示
     * @return mixed
     * @author fyl
     * @date 16-3-29 下午2:59
     */
    public function TransportList()
    {
        return  $this->mLogisticsLine->AdminTransportList();
    }

    /**
     * 物流路线添加
     * @param $paramObj
     * @return int
     */
    public function AddTransport($paramObj)
    {
        #添加分类
        $aData = [
            'departure'          =>     $paramObj->departure,
            'destination'        =>     $paramObj->destination,
            'model_type'         =>     $paramObj->model_type,
            'truck_length'       =>     $paramObj->truck_length,
            'truck_weight'       =>     $paramObj->truck_weight,
            'take_time'          =>     $paramObj->take_time,
            'spec_time'          =>     $paramObj->spec_time,
            'created'            =>     $paramObj->created,
        ];
        //dd($aData);
        return $this->mLogisticsLine->insert($aData);
    }

    /**
     * 物流路线单条查询
     * @param $paramObj
     * @return int
     */
    public function SelectOneTransport($paramObj)
    {
        $aData =  $paramObj->id;

        return $this->mLogisticsLine->GetLogisticsLineById($aData);
    }

    /**
     * 物流路线修改
     * @param $paramObj
     * @return int
     */
    public function UpdateTransport($paramObj)
    {
        #添加分类
        $aData = [
            'departure'          =>     $paramObj->departure,
            'destination'        =>     $paramObj->destination,
            'model_type'         =>     $paramObj->model_type,
            'truck_length'       =>     $paramObj->truck_length,
            'truck_weight'       =>     $paramObj->truck_weight,
            'take_time'          =>     $paramObj->take_time,
            'spec_time'          =>     $paramObj->spec_time,
            'created'            =>     $paramObj->created,
        ];

        return $this->mLogisticsLine->update($aData,['wl_id'=>$paramObj->wl_id]);
    }

    /**
     * 物流路线删除
     * @param $paramObj
     * @return int
     */
    public function DeleteOneTransport($paramObj)
    {
        return $this->mLogisticsLine->delete(['wl_id'=>$paramObj->wl_id]);
    }

    /**
     * 港口列表展示
     * @return mixed
     * @author fyl
     * @date 16-3-31 下午2:33
     */
    public function HarbourList()
    {
        return  $this->mHarbour->AdminHarbourList();
    }

    /**
     * 港口入庫
     * @param  $paramObj
     * @return int
     * @throws Exception
     * @author fyl
     * @date   2016-03-30
     */
    public function AddHarbour($paramObj)
    {
        #上传视频
        if(!empty($paramObj->video))
        {
            $paramObj->video = QiniuUpload::instance()->upload_files($paramObj->video);
            $aData2 = [
                'video_name'    =>  $paramObj->harbour_name,
                'video_url'     =>  $paramObj->video,
                'created'       =>  time(),
            ];
            $v_id = $this->mVideo->insert($aData2);
        }else{
            $v_id = "Null";
        }
        #上传图片
        if(!empty($paramObj->show_pic1))
            $paramObj->show_pic1 =  QiniuUpload::instance()->upload_files($paramObj->show_pic1);
        if(!empty($paramObj->show_pic2))
            $paramObj->show_pic2 =  QiniuUpload::instance()->upload_files($paramObj->show_pic2);
        if(!empty($paramObj->show_pic3))
            $paramObj->show_pic3 =  QiniuUpload::instance()->upload_files($paramObj->show_pic3);

        #汇总数据
        $aData = [
            'harbour_name'      =>   $paramObj->harbour_name,
            'city'              =>   $paramObj->city,
            'address'           =>   $paramObj->address,
            'quote'             =>   $paramObj->quote,
            'show_pic1'         =>   $paramObj->show_pic1,
            'show_pic2'         =>   $paramObj->show_pic2,
            'show_pic3'         =>   $paramObj->show_pic3,
            'video_id'          =>   $v_id,
            'introduce'         =>   $paramObj->introduce
        ];

        return $this->mHarbour->insert($aData);
    }

    /**
     * 港口信息修改
     * @param $paramObj
     * @return bool
     * @author fyl
     */
    public function UpdateHarbour($paramObj)
    {
        #图片上传
        $paramObj->show_pic1 = !empty($paramObj->show_pic1) ?
            $paramObj->show_pic1 =  QiniuUpload::instance()->upload_files($paramObj->show_pic1):$paramObj->show_pic1_old;
        $paramObj->show_pic2 = !empty($paramObj->show_pic2) ?
            $paramObj->show_pic2 =  QiniuUpload::instance()->upload_files($paramObj->show_pic2):$paramObj->show_pic2_old;
        $paramObj->show_pic3 = !empty($paramObj->show_pic3) ?
            $paramObj->show_pic3 =  QiniuUpload::instance()->upload_files($paramObj->show_pic3):$paramObj->show_pic3_old;

        #修改分类
        $aData = [
            'harbour_name'      =>   $paramObj->harbour_name,
            'city'              =>   $paramObj->city,
            'address'           =>   $paramObj->address,
            'quote'             =>   $paramObj->quote,
            'show_pic1'         =>   $paramObj->show_pic1,
            'show_pic2'         =>   $paramObj->show_pic2,
            'show_pic3'         =>   $paramObj->show_pic3,
            'introduce'         =>   $paramObj->introduce
        ];

        return $this->mHarbour->update($aData,['harbour_id'=>$paramObj->harbour_id]);
    }

    /**
     * 港口单条查询
     * @param $paramObj
     * @return int
     */
    public function SelectOneHarbour($paramObj)
    {
        $aData =  $paramObj->id;

        return $this->mHarbour->GetHarbourById($aData);
    }

    /**
     * 港口删除
     * @param $paramObj
     * @return int
     */
    public function DeleteOneHarbour($paramObj)
    {
        return $this->mHarbour->delete(['harbour_id'=>$paramObj->harbour_id]);
    }


    /**
     * 資訊列表展示
     * @return mixed
     * @author fyl
     * @date 16-04-01
     */
    public function NewsList()
    {
        return  $this->mInformation->AdminInformationList();
    }

    /**
     * 咨询入庫
     * @param  $paramObj
     * @return int
     * @throws Exception
     * @author fyl
     * @date   2016-04-01
     */
    public function AddNews($paramObj)
    {
        #上传图片
        if(!empty($paramObj->thumb_img1))
            $paramObj->thumb_img1 =  QiniuUpload::instance()->upload_files($paramObj->thumb_img1);
        if(!empty($paramObj->thumb_img2))
            $paramObj->thumb_img2 =  QiniuUpload::instance()->upload_files($paramObj->thumb_img2);
        if(!empty($paramObj->thumb_img3))
            $paramObj->thumb_img3 =  QiniuUpload::instance()->upload_files($paramObj->thumb_img3);

        #汇总数据
        $aData = [
            'title'              =>   $paramObj->title,
            'author'             =>   $paramObj->author,
            'source'             =>   $paramObj->source,
            'keywords'           =>   $paramObj->keywords,
            'thumb_img1'         =>   $paramObj->thumb_img1,
            'thumb_img2'         =>   $paramObj->thumb_img2,
            'thumb_img3'         =>   $paramObj->thumb_img3,
            'content'            =>   $paramObj->content,
            'cate'               =>   $paramObj->cate,
            'created'            =>   time(),
        ];
        return $this->mInformation->insert($aData);
    }

    /**
     * 港口信息修改
     * @param $paramObj
     * @return bool
     * @author fyl
     */
    public function UpdateNews($paramObj)
    {
        #图片上传
        $paramObj->thumb_img1 = !empty($paramObj->thumb_img1) ?
            $paramObj->thumb_img1 =  QiniuUpload::instance()->upload_files($paramObj->thumb_img1):$paramObj->thumb_img1_old;
        $paramObj->thumb_img2 = !empty($paramObj->thumb_img2) ?
            $paramObj->thumb_img2 =  QiniuUpload::instance()->upload_files($paramObj->thumb_img2):$paramObj->thumb_img2_old;
        $paramObj->thumb_img3 = !empty($paramObj->thumb_img3) ?
            $paramObj->thumb_img3 =  QiniuUpload::instance()->upload_files($paramObj->thumb_img3):$paramObj->thumb_img3_old;

        #修改分类
        $aData = [
            'title'              =>   $paramObj->title,
            'author'             =>   $paramObj->author,
            'source'             =>   $paramObj->source,
            'keywords'           =>   $paramObj->keywords,
            'thumb_img1'         =>   $paramObj->thumb_img1,
            'thumb_img2'         =>   $paramObj->thumb_img2,
            'thumb_img3'         =>   $paramObj->thumb_img3,
            'content'            =>   $paramObj->content,
            'cate'               =>   $paramObj->cate,
        ];
        return $this->mInformation->update($aData,['zx_id'=>$paramObj->zx_id]);
    }



    /**
     * 资讯单条查询
     * @param $paramObj
     * @return int
     */
    public function SelectOneNews($paramObj)
    {
        $aData =  $paramObj->id;
        return $this->mInformation->GetNewsById($aData);
    }


    /**
     * 港口删除
     * @param $paramObj
     * @return int
     */
    public function DeleteOneNews($paramObj)
    {
        return $this->mInformation->delete(['zx_id'=>$paramObj->zx_id]);
    }




    /**
     * 林场业务
     */

    /**
     * 列表显示
     * @return mixed
     * @author lizhongpeng
     * @date    2016-03-30
     */
    public function ShowForest()
    {
        return $this->mForest->GetForest();
    }
    /**
     * 林场列表删除
     */
    public function DeleteForest($aData)
    {
        if(!empty($aData->video_id))
          $this->mVideo->delete(['video_id'=>$aData->video_id]);

        return $this->mForest->delete(['forest_id' => $aData->id]);
    }

    /**
     * 林场服务
     * @param $paramObj
     * @return bool
     * @throws Exception
     */
    public function EditForest($paramObj)
    {
        #图片上传
        $paramObj->show_pic1 = !empty($paramObj->show_pic1) ?
            $paramObj->show_pic1 =  QiniuUpload::instance()->upload_files($paramObj->show_pic1):$paramObj->show_pic1_old;
        $paramObj->show_pic2 = !empty($paramObj->show_pic2) ?
            $paramObj->show_pic1 =  QiniuUpload::instance()->upload_files($paramObj->show_pic2):$paramObj->show_pic2_old;
        $paramObj->show_pic3 = !empty($paramObj->show_pic3) ?
            $paramObj->show_pic1 =  QiniuUpload::instance()->upload_files($paramObj->show_pic3):$paramObj->show_pic3_old;

        #修改分类
        $aData3 = [
            'forest_name'      => $paramObj->forest_name,
            'country'          => $paramObj->country,
            'product_cate'     => $paramObj->product_cate,
            'type'             => $paramObj->type,
            'introduce'        => $paramObj->introduce,
            'show_pic1'        => $paramObj->show_pic1,
            'show_pic2'        => $paramObj->show_pic2,
            'show_pic3'        => $paramObj->show_pic3
        ];

        return $this->mForest->update($aData3,['forest_id'=>$paramObj->forest_id]);
    }
    public function GetForestInfo($id)
    {
       return $this->mForest->GetForestInfo($id);

    }
    /**
     * 林场录入
     * @param  $paramObj
     * @return int
     * @throws Exception
     * @author lizhongpeng
     * @date   2016-03-30
     */
    public function AddForest($paramObj)
    {
        #上传视频
        if(!empty($paramObj->video))
        {
            $paramObj->video = QiniuUpload::instance()->upload_files($paramObj->video);
            $aData2 = [
                'video_name'    =>  $paramObj->forest_name,
                'video_url'     =>  $paramObj->video,
                'created'       =>  time(),
            ];
            $id = $this->mVideo->insert($aData2);
        }
        #上传图片
        if(!empty($paramObj->show_pic1))
            $paramObj->show_pic1 =  QiniuUpload::instance()->upload_files($paramObj->show_pic1);
        if(!empty($paramObj->show_pic2))
            $paramObj->show_pic2 =  QiniuUpload::instance()->upload_files($paramObj->show_pic2);
        if(!empty($paramObj->show_pic3))
            $paramObj->show_pic3 =  QiniuUpload::instance()->upload_files($paramObj->show_pic3);

        #汇总数据
        $aData = [
            'forest_name'      => $paramObj->forest_name,
            'country'          => $paramObj->country,
            'product_cate'     => $paramObj->product_cate,
            'type'             => $paramObj->type,
            'show_pic1'        => $paramObj->show_pic1,
            'show_pic2'        => $paramObj->show_pic2,
            'show_pic3'        => $paramObj->show_pic3,
            //'video_id'         => $id,
            'introduce'        => $paramObj->introduce
        ];

        return $this->mForest->insert($aData);
    }
    /**
     *仓储服务
     * @throws Exception
     * @author lizhongpeng
     * @date   2016-03-030
     */
    public function ShowStorage()
    {
        return $this->mStorage->GetStorage();
    }
    /**
     * 仓储列表删除
     * @return mixed
     * @author lzhp
     * @date  2016-04-01
     */
    public function StorageDelete($aData)
    {
        if(!empty($aData->video_id))
            $this->mVideo->delete(['video_id'=>$aData->video_id]);

        return $this->mStorage->delete(['storage_id' => $aData->id]);
    }

    /**
     *
     */
    public function GetStorageInfo($id)
    {
        return $this->mStorage->GetStorageInfo($id);
    }

    /**
     *仓储添加
     * @return mixed
     * @author lzhp
     * @date  2016-04-01
     */
    public function StorageAdd($paramObj)
    {
        #上传图片
        if(!empty($paramObj->show_pic1))
            $paramObj->show_pic1 =  QiniuUpload::instance()->upload_files($paramObj->show_pic1);
        if(!empty($paramObj->show_pic2))
            $paramObj->show_pic2 =  QiniuUpload::instance()->upload_files($paramObj->show_pic2);
        if(!empty($paramObj->show_pic3))
            $paramObj->show_pic3 =  QiniuUpload::instance()->upload_files($paramObj->show_pic3);

        #汇总数据
        $aData = [
            'storage_name'      => $paramObj->storage_name,
            'storage_address'   => $paramObj->storage_address,
            'quote'             => $paramObj->quote,
            'introduce'         => $paramObj->introduce,
            'show_pic1'         => $paramObj->show_pic1,
            'show_pic2'         => $paramObj->show_pic2,
            'show_pic3'         => $paramObj->show_pic3,
        ];

        return $this->mStorage->insert($aData);
    }

    /**
     *仓储修改
     * @return mixed
     * @author lzhp
     * @date  2016-04-01
     */
    public function StorageUp($paramObj)
    {
        #图片上传
        $paramObj->show_pic1 = !empty($paramObj->show_pic1) ?
            $paramObj->show_pic1 =  QiniuUpload::instance()->upload_files($paramObj->show_pic1):$paramObj->show_pic1_old;
        $paramObj->show_pic2 = !empty($paramObj->show_pic2) ?
            $paramObj->show_pic2 =  QiniuUpload::instance()->upload_files($paramObj->show_pic2):$paramObj->show_pic2_old;
        $paramObj->show_pic3 = !empty($paramObj->show_pic3) ?
            $paramObj->show_pic3 =  QiniuUpload::instance()->upload_files($paramObj->show_pic3):$paramObj->show_pic3_old;

        #修改分类
        $aData3 = [
            'storage_name'      => $paramObj->storage_name,
            'storage_address'   => $paramObj->storage_address,
            'quote'             => $paramObj->quote,
            'introduce'         => $paramObj->introduce,
            'show_pic1'         => $paramObj->show_pic1,
            'show_pic2'         => $paramObj->show_pic2,
            'show_pic3'         => $paramObj->show_pic3
        ];

        return $this->mStorage->update($aData3,['storage_id'=>$paramObj->storage_id]);
    }
    /**
     * 文章列表
     * @return mixed
     * @author lzhp
     * @date  2016-04-01
     */
    public function ArticleList()
    {
        return $this->mHelpCenter->GetArticle();
    }
    /**
     * 文章删除
     * @return mixed
     * @author lzhp
     * @date  2016-04-01
     */
    public function ArticleDelete($aData)
    {
        return $this->mHelpCenter->delete(['help_id' => $aData->id]);
    }
    /**
     * 文章添加
     * @return mixed
     * @author lzhp
     * @date  2016-04-01
     */
    public function ArticleAdd($paramObj)
    {
        #汇总数据
        $aData = [
            'title'      =>  $paramObj->title,
            'content'    =>  $paramObj->content,
            'type'       =>  $paramObj->type,

        ];

        return $this->mHelpCenter->insert($aData);
    }
    /**
     * 文章修改
     * @return mixed
     * @author lzhp
     * @date  2016-04-01
     */
    public function ArticleUp($paramObj)
    {
        #修改分类
        $aData3 = [
            'title'      =>  $paramObj->title,
            'content'    =>  $paramObj->content,
            'type'       =>  $paramObj->type,
        ];
        return $this->mHelpCenter->update($aData3,['help_id'=>$paramObj->help_id]);
    }
    public function GetArticleId($id)
    {
        return $this->mHelpCenter->GetArticleId($id);
    }
    /**
     * 会员列表
     * @return mixed
     * @author lzhp
     * @date  2016-04-04
     */
    public function ManagerUser()
    {
        return $this->mUser->fetchAll([],[],['user_id' => 'desc']);
    }

    /**
     * 会员下拉菜单
     * @return mixed
     * @author fyl
     * @date  2016-05-26
     */
    public function UserSelect()
    {
        return $this->mUser->UserSelect();
    }


    /**
     * 会员添加
     * @param $paramObj
     * @return int
     * @throws Exception
     */
    public function CustomerAdd($paramObj)
    {
        if(empty($paramObj->password))
            return Redirect::to('/customer_import');
        if(!empty($paramObj->avatar))
            $paramObj->avatar =  QiniuUpload::instance()->upload_files($paramObj->avatar);
        $aData = [
            'user_name'      => $paramObj->user_name,
            'mobile'         => $paramObj->mobile,
            'avatar'         => $paramObj->avatar,
            'password'       => md5($paramObj->password),
            'created'        => time()
        ];
        return $this->mUser->insert($aData);
    }

    /**
     * 会员删除
     * @return mixed
     * @author lzhp
     * @date  2016-04-04
     */
    public function CustomerDelete($aData)
    {

        return $this->mUser->delete(['user_id'=>$aData->user_id]);
    }

    /**
     * 会员ajax返回
     * @return mixed
     * @author lzhp
     * @date  2016-04-04
     */
    public function GetUserInfo($id)
    {
        return $this->mUser->GetUserInfo($id);
    }

    /**
     * 会员修改
     * @return mixed
     * @author lzhp
     * @date  2016-04-04
     */
    public function CustomerUp($paramObj)
    {
        #图片上传
        $paramObj->avatar = !empty($paramObj->avatar) ?
            $paramObj->avatar =  QiniuUpload::instance()->upload_files($paramObj->avatar):$paramObj->avatar_old;

        #修改分类
        $aData = [
            'user_name'      => $paramObj->user_name,
            'mobile'         => $paramObj->mobile,
            'avatar'         => $paramObj->avatar,
            'password'       => $paramObj->password
        ];

        return $this->mUser->update($aData,['user_id'=>$paramObj->user_id]);
    }

    /**
     * 管理员列表
     * @return mixed
     * @author lzhp
     * @date  2016-04-04
     */
    public function ManageAdmin()
    {
        return $this->mAdmin->ManageAdmin();

    }

    /**
     * 管理员添加
     * @param $paramObj
     * @return int
     * @throws Exception
     */
    public function AdminAdd($paramObj)
    {
        if(empty($paramObj->password))
            return Redirect::to('/add_admin');
        if($paramObj->password!==$paramObj->sure)
            return Redirect::to('/add_admin');
        if(!empty($paramObj->avatar))
            $paramObj->avatar =  QiniuUpload::instance()->upload_files($paramObj->avatar);
        $aData = [
            'name'           => $paramObj->name,
            'real_name'      => $paramObj->real_name,
            'mobile'         => $paramObj->mobile,
            'avatar'         => $paramObj->avatar,
            'password'       => md5($paramObj->password),
            'role_id'        => $paramObj->role_id,
            'status'         => $paramObj->status,
            'created'        => time()
        ];
        return $this->mAdmin->insert($aData);
    }

    /**
     * 管理员编辑
     * @return mixed
     * @author lzhp
     * @date  2016-04-04
     */
    public function GetAdminInfo($id)
    {
        return $this->mAdmin->GetAdminInfo($id);
    }
    public function AdminUp($paramObj)
    {
        if($paramObj->password!==$paramObj->sure)
            return Redirect::to('/edit_admin');
        #图片上传
        $paramObj->avatar = !empty($paramObj->avatar) ?
            $paramObj->avatar =  QiniuUpload::instance()->upload_files($paramObj->avatar):$paramObj->avatar_old;

        #修改分类
        $aData = [
            'name'           => $paramObj->name,
            'real_name'      => $paramObj->real_name,
            'mobile'         => $paramObj->mobile,
            'avatar'         => $paramObj->avatar,
            'password'       => md5($paramObj->password),
            'role_id'        => $paramObj->role_id,
            'status'         => $paramObj->status,
            'created'        => time()
        ];
        return $this->mAdmin->update($aData,['id'=>$paramObj->id]);
    }

    /**
     * 管理员删除
     * @return mixed
     * @author lzhp
     * @date  2016-04-04
     */
    public function DeleteAdmin($aData)
    {
        return $this->mAdmin->delete(['id'=>$aData->id]);
    }
    /**
     * 管理员角色列表
     * @return mixed
     * @author lzhp
     * @date  2016-04-04
     */
    public function ManageAdminRole()
    {
        return $this->mRole->ManageAdminRole();
    }
    /**
     * 管理员角色添加
     * @return mixed
     * @author lzhp
     * @date  2016-04-04
     */
    public function RoleAdd($paramObj)
    {
        $aData = [
            'role_name'        =>   $paramObj->role_name,
            'privilege'        =>   $paramObj->privilege
        ];

        return $this->mRole->insert($aData);
    }
    /**
     * 管理员角色编辑
     * @return mixed
     * @author lzhp
     * @date  2016-04-04
     */
    public function GetRoleId($id)
    {

        return $this->mRole->GetRoleId($id);
    }

    /**
     *管理员角色修改
     * @return mixed
     * @author lzhp
     * @date  2016-04-04
     */
    public function RoleUp($paramObj)
    {
        #修改分类
        $aData = [
            'role_name'        =>   $paramObj->role_name,
            'privilege'        =>   $paramObj->privilege
        ];

        return $this->mRole->update($aData,['role_id'=>$paramObj->role_id]);
    }
    /**
     * 管理员角色删除
     * @return mixed
     * @author lzhp
     * @date  2016-04-04
     */
    public function DeleteAdminRole($paramObj)
    {
        return $this->mRole->delete(['role_id'=>$paramObj->role_id]);
    }


    /**
     * 日志列表
     * @return mixed
     * @author lzhp
     * @date  2016-04-04
     */
    public function LogService()
    {
        return $this->mLog->LogService();
    }



    /**
     * 日志删除
     * @return mixed
     * @author lzhp
     * @date  2016-04-04
     */
    public function DeleteLog($aData)
    {
        return $this->mLog->delete(['log_id'=>$aData->log_id]);
    }

    /**
     * 商家列表展示
     * @@return mixed
     * @author lzhp
     * @date  2016-04-05
     */
    public function ManageSupplier()
    {
        return $this->mSupplier->ManageSupplier();
    }

    /**
     * 商家列表展示
     * @@return mixed
     * @author lzhp
     * @date  2016-04-05
     */
    public function SupplierInfo()
    {
        return $this->mSupplier->SupplierInfo();
    }

    /**
     * 添加商家
     * @return mixed
     * @author lzhp
     * @date  2016-04-05
     */
    public function SupplierAdd($paramObj)
    {
        if(!empty($paramObj->operate_license))
            $paramObj->operate_license =  QiniuUpload::instance()->upload_files($paramObj->operate_license);
        if(!empty($paramObj->tax_license))
            $paramObj->tax_license =  QiniuUpload::instance()->upload_files($paramObj->tax_license);
        if(!empty($paramObj->show_img1))
            $paramObj->show_img1 =  QiniuUpload::instance()->upload_files($paramObj->show_img1);
        if(!empty($paramObj->show_img2))
            $paramObj->show_img2 =  QiniuUpload::instance()->upload_files($paramObj->show_img2);
        if(!empty($paramObj->show_img3))
            $paramObj->show_img3 =  QiniuUpload::instance()->upload_files($paramObj->show_img3);
        $aData = [
            'supplier_id'            =>     $paramObj->user_id,
            'supplier_name'          =>     $paramObj->supplier_name,
            'company'                =>     $paramObj->company,
            'address'                =>     $paramObj->address,
            'address_all'            =>     $paramObj->address_all,
            'phone'                  =>     $paramObj->phone,
            'operate_license'        =>     $paramObj->operate_license,
            'show_img1'              =>     $paramObj->show_img1,
            'show_img2'              =>     $paramObj->show_img2,
            'show_img3'              =>     $paramObj->show_img3,
            'created'                =>     time()

        ];
        $this->mUser->update(['is_supplier'=>1],['user_id'=>$paramObj->user_id]);
        return $this->mSupplier->insert($aData);
    }



    /**
     * 修改商家
     * @return mixed
     * @author lzhp
     * @date  2016-04-05
     */
    public function SupplierUp($paramObj)
    {
        #图片上传
        $paramObj->operate_license = !empty($paramObj->operate_license) ?
            $paramObj->operate_license =  QiniuUpload::instance()->upload_files($paramObj->operate_license):$paramObj->operate_license_old;
        $paramObj->tax_license = !empty($paramObj->tax_license) ?
            $paramObj->tax_license =  QiniuUpload::instance()->upload_files($paramObj->tax_license):$paramObj->tax_license_old;
        $paramObj->show_img1 = !empty($paramObj->show_img1) ?
            $paramObj->show_img1 =  QiniuUpload::instance()->upload_files($paramObj->show_img1):$paramObj->show_img1_old;
        $paramObj->show_img2 = !empty($paramObj->show_img2) ?
            $paramObj->show_img2 =  QiniuUpload::instance()->upload_files($paramObj->show_img2):$paramObj->show_img2_old;
        $paramObj->show_img3 = !empty($paramObj->show_img3) ?
            $paramObj->show_img3 =  QiniuUpload::instance()->upload_files($paramObj->show_img3):$paramObj->show_img3_old;
        #修改分类
        $aData = [
            'supplier_name'          =>     $paramObj->supplier_name,
            'company'                =>     $paramObj->company,
            'owner'                  =>     $paramObj->owner,
            'address'                =>     $paramObj->address,
            'phone'                  =>     $paramObj->phone,
            'brand'                  =>     $paramObj->brand,
            'scale'                  =>     $paramObj->scale,
            'id_card'                =>     $paramObj->id_card,
            'bank_account'           =>     $paramObj->bank_account,
            'operate_license'        =>     $paramObj->operate_license,
            'tax_license'            =>     $paramObj->tax_license,
            'show_img1'              =>     $paramObj->show_img1,
            'show_img2'              =>     $paramObj->show_img2,
            'show_img3'              =>     $paramObj->show_img3,
            'market'                 =>     $paramObj->market,
            'feature'                =>     $paramObj->feature,
            'storage'                =>     $paramObj->storage,
            'business_scope'         =>     $paramObj->business_scope,
            'brief'                  =>     $paramObj->brief,
            'is_foreign'             =>     $paramObj->is_foreign,
            'created'                =>     time()
        ];

        return $this->mSupplier->update($aData,['supplier_id'=>$paramObj->supplier_id]);
    }
    /**
     * 删除替换
     * @return mixed
     * @author lzhp
     * @date  2016-04-05
     */
    public function GeSupplierId($supplier_id)
    {
        return $this->mSupplier->GeSupplierId($supplier_id);
    }

    /**
     * 删除商家
     * @return mixed
     * @author lzhp
     * @date  2016-04-05
     */
    public function DelSupplier($aData)
    {
        return $this->mSupplier->delete(['supplier_id'=>$aData->supplier_id]);
    }

    /**
     * 修改用户商家状态
     * @return mixed
     * @author fyl
     * @date  2016-04-05
     */
    public function UpdateUserSupplierStatus($aData)
    {
        return $this->mUser->update(['user_id'=>$aData->supplier_id],['is_supplier'=>0]);
    }

    /**
     * 获取商家审核列表
     * @return mixed
     * @author lzhp
     * @date  2016-04-05
     */
    public function SupplierExamineList()
    {
        return $this->mSupplier->GetSupplierExamine(ProductEnum::PRODUCT_EXAMINE_ING);
    }

    /**
     * 获取商家审核列表
     * @return mixed
     * @author lzhp
     * @date  2016-04-05
     */
    public function GetSupplierInfo($supplier_id)
    {
        return $this->mSupplier->GetSupplierInfo($supplier_id);
    }

    /**
     * 商家审核结果
     * @param $paramObj
     * @return int
     */
    public function SupplieUpdateStatus($paramObj)
    {
        #修改分类
        $aData = [
            'status'               =>      $paramObj->status,
            'examine'              =>      $paramObj->examine,
            'created'              =>      time(),
        ];
        if($aData['status']==1){
            $this->mUser->update(['is_supplier'=>1],['user_id'=>$paramObj->supplier_id]);
        }
        return $this->mSupplier->update($aData,['supplier_id'=>$paramObj->supplier_id]);
    }

    /**
     * 订单列表
     * @return mixed
     * @author lzhp
     * @date  2016-04-05
     */
    public function OrderList()
    {
        return $this->mOrder->OrderList();
    }
    /**
     * 询价单列表
     * @return mixed
     * @author lzhp
     * @date  2016-04-05
     */
    public function InquiryList()
    {
        return $this->mInquiry->InquiryList();
    }
    /**
     * 定制单列表
     * @return mixed
     * @author lzhp
     * @date  2016-04-05
     */
    public function CustomizeList()
    {
       $info = $this->mCustomize->CustomizeList();
        foreach($info as &$v){
            if($v->admin_id){
                $v->admin_id = $this->mAdmin->getAdminName($v->admin_id)->real_name;
            }
        }
        return $info;
    }

    /**
     * 定制单详情
     * @return mixed
     * @author fyl
     * @date  2016-06-01
     */
    public function CustomizeOne($aData)
    {
        return $this->mCustomize->CustomizeOne($aData->customize_id);
    }

    /**
     * 修改定制单
     * @return mixed
     * @author fyl
     * @date  2016-06-01
     */
    public function CustomizeUpdate($aData)
    {
        $admin_id = Session::get(UserEnum::ADMIN_USER_KEY_ID);
        return $this->mCustomize->update(['status'=>$aData->status,'admin_id'=>$admin_id,'outcome'=>$aData->outcome],['customize_id'=>$aData->customize_id]);
    }

    /**
     * 供货单列表
     * @return mixed
     * @author lzhp
     * @date  2016-04-05
     */
    public function SupplyList()
    {
        return $this->mSupply->SupplyList();
    }


    /**---------------------------------产品------------------------------------*/

    /**
    产品列表
    */
    public function ShowProduct(){
        return $this->mProduct->AdminProductList();
    }


    /**
    产品审核列表
     */
    public function ProductExamineList(){
        return $this->mProduct->ProductExamineList();
    }


    /**
     *产品添加
     */
    public function AddProduct($paramObj)
    {
        #上传图片
        if(!empty($paramObj->product_img))
            $paramObj->product_img =  QiniuUpload::instance()->upload_files($paramObj->product_img);
        if(!empty($paramObj->show_pic1))
            $paramObj->show_pic1 =  QiniuUpload::instance()->upload_files($paramObj->show_pic1);
        if(!empty($paramObj->show_pic2))
            $paramObj->show_pic2 =  QiniuUpload::instance()->upload_files($paramObj->show_pic2);
        #汇总数据
        $aData = [
            'product_name'      => $paramObj->product_name,
            'supplier_id'       => $paramObj->supplier_id,
            'stock'             => $paramObj->stock,
            'quality'          =>$paramObj->quality,
            'classes'           => $paramObj->classes,
            'unit'              => $paramObj->unit,
            'category'          => $paramObj->category,
            'price'             => $paramObj->price,
            'level'             => $paramObj->level,
            'description'       => $paramObj->description,
            'place'             => $paramObj->place,
            'spec'              => $paramObj->spec,
            'storage'           => $paramObj->storage,
            'phone'           => $paramObj->phone,
            'start_num'         => $paramObj->start_num,
            'product_img'       => $paramObj->product_img,
            'product_sn'        => ToolKit::make_product_sn(),
            'created'           => time(),
        ];
        $product_id = $this->mProduct->insert($aData);
        #插入产品媒体库
        $data = [
            'product_id' => $product_id,
            'show_img2' => empty($paramObj->show_pic1) ?'' : $paramObj->show_pic1,
            'show_img3' => empty($paramObj->show_pic2) ? '' : $paramObj->show_pic2,
            'show_img1' => empty($paramObj->product_img) ? '' : $paramObj->product_img
        ];

        return $this->mProductPic->insert($data);
    }

    /**
     * 产品修改
     * @param $paramObj
     * @return int
     */
    public function UpdateProduct($paramObj)
    {
        #图片上传
        $paramObj->product_img = !empty($paramObj->product_img) ?
            $paramObj->product_img =  QiniuUpload::instance()->upload_files($paramObj->product_img):$paramObj->product_img_old;
        $paramObj->show_pic1 = !empty($paramObj->show_pic1) ?
            $paramObj->show_pic1 =  QiniuUpload::instance()->upload_files($paramObj->show_pic1):$paramObj->product_pic1_old;
        $paramObj->show_pic2 = !empty($paramObj->show_pic2) ?
            $paramObj->show_pic2 =  QiniuUpload::instance()->upload_files($paramObj->show_pic2):$paramObj->product_pic2_old;
   /*     #获取分类
        $classes  = $this->mProductCate->GetProductCateParentId($paramObj->quality);
        $category = $this->mProductCate->GetProductCateParentId($classes->parent_id);*/
        #修改分类
        $aData3 = [
            'product_name'      => $paramObj->product_name,
            'stock'             => $paramObj->stock,
            'classes'           => $paramObj->classes,
            'category'          => $paramObj->category,
            'price'             => $paramObj->price,
            'unit'              => $paramObj->unit,
            'description'       => $paramObj->description,
            'place'             => $paramObj->place,
            'spec'              => $paramObj->spec,
            'storage'           => $paramObj->storage,
            'phone'             => $paramObj->phone,
            'start_num'         => $paramObj->start_num,
            'product_img'       => $paramObj->product_img,
        ];
        $this->mProduct->update($aData3,['product_id'=>$paramObj->product_id]);
        $data = [
            'show_img2' => empty($paramObj->show_pic1) ?'' : $paramObj->show_pic1,
            'show_img3' => empty($paramObj->show_pic2) ? '' : $paramObj->show_pic2,
            'show_img1' => empty($paramObj->product_img) ? '' : $paramObj->product_img
        ];
        return $this->mProductPic->update($data,['product_id'=>$paramObj->product_id]);
    }

    /**
     * 商品删除
     * @param $paramObj
     * @return int
     */
    public function DeleteOneProduct($paramObj)
    {
        return $this->mProduct->delete(['product_id'=>$paramObj->product_id]);
    }



    /**
     * 产品单条查询
     * @param $paramObj
     * @return int
     */
    public function SelectOneProduct($paramObj)
    {
        $aData =  $paramObj->product_id;
        return $this->mProduct->AdminGetProductById($aData);
    }
    /**
     * 联动
     */
    public function linkage($id){

        $info = $this->mProductCate->linkage($id);
        foreach($info as $info1){
            $rs[] = $info1;
        }
        return $rs;

    }
    public function GetName($cate_id){
        return $this->mProductCate->GetName($cate_id);

    }

    /**
     * 产品单条查询
     * @param $paramObj
     * @return int
     */
    public function UpdateStatus($paramObj)
    {
        #修改分类
        $aData = [
            'status'               =>      $paramObj->status,
            'examine'              =>      $paramObj->examine,
        ];
        return $this->mProduct->update($aData,['product_id'=>$paramObj->product_id]);
    }

    /**
     * 地区修改
     * @param $paramObj
     * @return int
     */
    public function ProductUpdateAction($paramObj)
    {
        #修改分类
        $aData3 = [
            'area_name'            =>      $paramObj->area_name,
            'country'              =>      $paramObj->country,
        ];
        return $this->mProductArea->update($aData3,['area_id'=>$paramObj->area_id]);
    }


    /**
    产品地区列表
     */
    public function ShowProductArea(){
        return $this->mProductArea->AdminProductAreaList();
    }

    /**
    产品规格列表
     */
    public function ShowProductSpec(){
        return $this->mSpec->AdminProductSpecList();
    }

    /**
    产品等级列表
     */
    public function ShowProductLevel(){
        return $this->mLevel->AdminProductLevelList();
    }

    /**
     * 产地单条查询
     * @param $paramObj
     * @return int
     */
    public function SelectOneProductPlace($paramObj)
    {
        $aData =  $paramObj->area_id;
        return $this->mProductArea->GetProductAreaById($aData);
    }


    /**
     *地区添加
     */
    public function AddProductPlace($paramObj)
    {
        #汇总数据
        $aData = [
            'area_name'           => $paramObj->area_name,
            'country'             => $paramObj->country,
        ];
        return $this->mProductArea->insert($aData);
    }

    /**
     * 地区修改
     * @param $paramObj
     * @return int
     */
    public function UpdateProductPlace($paramObj)
    {
        #修改分类
        $aData3 = [
            'area_name'            =>      $paramObj->area_name,
            'country'              =>      $paramObj->country,
        ];
        return $this->mProductArea->update($aData3,['area_id'=>$paramObj->area_id]);
    }

    /**
     * 品牌删除
     * @param $paramObj
     * @return int
     */
    public function DeleteOneProductArea($paramObj)
    {
        return $this->mProductArea->delete(['area_id'=>$paramObj->area_id]);
    }

    /**
    产品品牌列表
     */
    public function ShowProductBrand(){
        return $this->mProductBrand->AdminProductBrandList();
    }

    /**
     *品牌添加
     */
    public function AddProductBrand($paramObj)
    {
        #上传图片
        if(!empty($paramObj->brand_img))
            $paramObj->brand_img =  QiniuUpload::instance()->upload_files($paramObj->brand_img);

        #汇总数据
        $aData = [
            'brand_name'        => $paramObj->brand_name,
            'quality'           => $paramObj->quality,
            'is_show'           => $paramObj->is_show,
            'brand_img'         => $paramObj->brand_img,
            'created'           => time(),
        ];
        return $this->mProductBrand->insert($aData);
    }

    /**
     * 品牌修改
     * @param $paramObj
     * @return int
     */
    public function UpdateProductBrand($paramObj)
    {
        #图片上传
        $paramObj->brand_img = !empty($paramObj->brand_img) ?
            $paramObj->brand_img =  QiniuUpload::instance()->upload_files($paramObj->brand_img):$paramObj->brand_img_old;

        #修改分类
        $aData3 = [
            'brand_img'            =>      $paramObj->brand_img,
            'brand_name'           =>      $paramObj->brand_name,
            'quality'              =>      $paramObj->quality,
            'is_show'              =>      $paramObj->is_show,
        ];
        return $this->mProductBrand->update($aData3,['brand_id'=>$paramObj->brand_id]);
    }

    /**
     * 品牌单条查询
     * @param $paramObj
     * @return int
     */
    public function SelectOneProductBrand($paramObj)
    {
        $aData =  $paramObj->brand_id;
        return $this->mProductBrand->GetProductBrandById1($aData);
    }


    /**
     * 品牌删除
     * @param $paramObj
     * @return int
     */
    public function DeleteOneProductBrand($paramObj)
    {
        $re = $this->mProduct->GetProductBrand($paramObj->brand_id);
        if($re){
            return  0;
        }else{
            return $this->mProductBrand->delete(['brand_id'=>$paramObj->brand_id]);
        }
    }


    /**
    产品分类列表
     */
    public function ShowProductCate(){
        return $this->mProductCate->AdminProductCateList();
    }

    /**
    产品全部分类列表
     */
    public function ShowProductCateAll(){
        return $this->mProductCate->AdminProductCateAllList();


    }

    /**
   缓存分类列表
     */
    public function CacheCate(){
            #获取分类
            $Category = $this->mProductCate->GetProductCategory();
            $category = [];
            foreach ($Category as $cate) {
                #获取品类
                $classes = $this->mProductCate->GetProductClasses($cate->cate_id);
                $classes_list = [];
                foreach ($classes as $v){
                    #获取材质
                    $quality = $this->mProductCate->GetProductQuality($v->cate_id);
                    $quality_list = [];
                    foreach ($quality as $q) {
                           #获取规格
                        //  $spec = $this->mSpec->GetSpecList($q->cate_id);

                          #获取等级
                        //  $level = $this->mLevel->GetLevelList($q->cate_id);
                        $quality_list[] = [
                            'id'    => $q->cate_id,
                            'name'  => $q->cate_name,
                            /*  'spec'  => $spec,
                              'level' => $level,*/
                        ];
                    }
                    $classes_list[] = [
                        'id'         => $v->cate_id,
                        'name'       => $v->cate_name,
                        'quality'    => $quality_list
                    ];
                }

                $category[] = [
                    'id' => $cate->cate_id,
                    'name' => $cate->cate_name,
                    'classes' => $classes_list
                ];
            }
        Cache::forever('cache_cate', $category);
        return 1;
    }



    /**
     * 分类单条查询
     * @param $paramObj
     * @return int
     */
    public function SelectOneProductCate($paramObj)
    {
        $aData =  $paramObj->cate_id;
        return $this->mProductCate->GetProductCateById($aData);
    }
    public function UpdateProductCate($paramObj){
        $cate_id=$paramObj->cate_id;
        $aData =  [
            'cate_name'          =>     $paramObj->cate_name,
            'parent_id'          =>     $paramObj->parent_id,
            'length'             =>     $paramObj->length,
            //'remark '            => 0 ,
        ];

        return $this->mProductCate->UpdateProductCate($cate_id,$aData);

    }

    /**
     * 分类删除
     * @param $paramObj
     * @return int
     */
    public function DeleteOneProductCate($paramObj)
    {
        $re = $this->mProductCate->GetProductCateParent($paramObj->cate_id);
        if($re){
            return  0;
        }else{
            return $this->mProductCate->delete(['cate_id'=>$paramObj->cate_id]);
        }
    }


    /**
     产品材质列表
     */
    public function ShowProductCateQuality(){
        return $this->mProductCate->AdminProductCateQualityList();
    }

    /**
    产品品类列表
     */
    public function ShowProductCateClasses(){
        return $this->mProductCate->AdminProductCateClassesList();
    }


    /**
     产品等级入库
     */
    public function AddProductLevel($paramObj)
    {
        #添加分类
        $aData = [
            'level_name'          =>     $paramObj->level_name,
            'quality'             =>     $paramObj->quality,
            'sort_by'             =>     $paramObj->sort_by,
        ];
        //dd($aData);
        return $this->mLevel->insert($aData);
    }

    /**
    产品规格入库
     */
    public function AddProductSpec($paramObj)
    {
        #添加分类
        $aData = [
            'spec_name'          =>     $paramObj->spec_name,
            'quality'             =>     $paramObj->quality,
            'sort_by'             =>     $paramObj->sort_by,
        ];
        //dd($aData);
        return $this->mSpec->insert($aData);
    }

    /**
    产品材质入库
     */
    public function AddProductCate($paramObj)
    {
        $aData = [
            'cate_name'           =>     $paramObj->cate_name,
            'parent_id'           =>     $paramObj->parent_id,
            'rank'                =>     $paramObj->rank,
            'length'              =>     $paramObj->length,
        ];
        #添加分类
        if($paramObj->cate_id){
           return $this->mProductCate->update($aData,['cate_id'=>$paramObj->cate_id]);
        }else{
            return $this->mProductCate->insert($aData);
        }

    }



    /**
     * 广告位列表
     */
    public function AdsList()
    {
        return $this->mAds->AdsList();
    }

    /**
     * 广告位添加
     * @param $paramObj
     * @return int
     */
    public function AdsAdd($paramObj)
    {
        if(!empty($paramObj->img))
            $paramObj->img =  QiniuUpload::instance()->upload_files($paramObj->img);
        #添加
        $aData = [
            'ads_name'          =>     $paramObj->ads_name,
            'img'               =>     $paramObj->img,
            'type'              =>     $paramObj->type,
            'is_rec'            =>     $paramObj->is_rec,
            'order_by'          =>     $paramObj->order_by,
            'link'              =>     $paramObj->link,
            'created'           =>     time(),
        ];
        //dd($aData);
        return $this->mAds->insert($aData);
    }
    public function AdsUp($paramObj)
    {
        #图片上传

        $paramObj->img = !empty($paramObj->img) ?
            $paramObj->img =  QiniuUpload::instance()->upload_files($paramObj->img):$paramObj->img_old;
        #修改
        $aData = [
            'ads_name'          =>     $paramObj->ads_name,
            'img'               =>     $paramObj->img,
            'type'              =>     $paramObj->type,
            'is_rec'            =>     $paramObj->is_rec,
            'order_by'          =>     $paramObj->order_by,
            'link'              =>     $paramObj->link,
        ];

        return $this->mAds->update($aData,['ads_id'=>$paramObj->ads_id]);

    }
    public function GetAdsInfo($ads_id)
    {
        return $this->mAds->GetAdsInfo($ads_id);
    }
    public function DelAds($paramObj)
    {
        return $this->mAds->delete(['ads_id'=>$paramObj->ads_id]);
    }
    public function AdsAjax()
    {
        return $this->mAds->AdsList();
    }


    /**
     *林场直供列表
     * @return mixed
     * @author fyl
     * @date 2016-04-12
     */
    public function ForestNeed()
    {
        return $this->mForestNeed->ForestNeedList();
    }

    /**
     *港口需求列表
     * @return mixed
     * @author fyl
     * @date 2016-04-12
     */
    public function HarbourNeed()
    {
        return $this->mHarbourNeed->HarbourNeedList();
    }


    /**
     *仓储需求列表
     * @return mixed
     * @author fyl
     * @date 2016-04-12
     */
    public function StorageNeed()
    {
        return $this->mStorageNeed->StorageNeedList();
    }
    /**
     *
     * 采购列表
     *
     */
    public function PurchaseResource(){
        return $this->mPurchaseResource->PurchaseResource1();

    }
    /**
     *
     * 采购详情
     */
    public function PurchaseResourceDetails($purchase_id){
        return $this->mPurchaseResource->PurchaseResourceDetails($purchase_id);

    }
    /**
     *
     * 采购审核
     */
    public function PurchaseResourceExamine($examine,$purchase_id,$title,$spec,$num,$unit,$price,$place,$contacts,$tell,$company){
        $result = $this->mPurchaseResource->PurchaseResourceExamine($examine,$purchase_id,$title,$spec,$num,$unit,$price,$place,$contacts,$tell,$company);
        return $result;

    }

    /**
     *现货列表
     */
    public function NewResource(){
        return $this->mNewResource->AdminNewResourceList();

    }

    /**
     * 删除现货
     * @return mixed
     * @author fyl
     * @date  2016-04-05
     */
    public function DeleteNewResource($aData)
    {
        return $this->mNewResource->delete(['product_id'=>$aData->product_id]);
    }

    /**
     *现货详情
     */
    public function NewResourceInfo($aData){
        $info = $this->mNewResource->NewResourceDetails($aData);
        $img  = $this->mProductPic->DetailsPic($aData);
        $info->show_img1 = $img->show_img1;
        $info->show_img2 = $img->show_img2;
        $info->show_img3 = $img->show_img3;
        return $info;

    }


    /**
     * 现货审核结果
     * @param $paramObj
     * @return int
     */
    public function NewResourceUpdateStatus($paramObj)
    {
        #修改分类
        $aData = [
            'status'               =>      $paramObj->status,
            'examine'              =>      $paramObj->examine,
            'created'              =>      time(),
        ];
        return $this->mNewResource->update($aData,['product_id'=>$paramObj->product_id]);
    }

    /**
     * 获取邀请码
     */
    public function GetInviteCode() {
        list($s1, $s2) = explode(' ', microtime());
        return substr(sprintf('%.0f', (floatval($s1) * floatval($s2)) * 10000),0,12);
    }



    /**
     * 获取邀请码
     */
    public function AddInviteCode() {

        for($i=0;$i<=200;$i++){
            $invite_code['invite_code'] = $this->GetInviteCode();
             $this->mInviteCode->insert($invite_code);
        }
        return 1;
    }

    /**
     * 反馈列表
     * @return stdClass
     * @date 2016-03-03
     * @author fyl
     */
    public function GetFeedbackList()
    {
        $feedback = $this->mFeedback->GetFeedbackList();
        foreach($feedback as &$v){
            if(!empty($v->user_id)){
               $user_name = $this->mUser->GetUserName($v->user_id);
                if(!$user_name){
                    $v->user_id = "匿名";
                }else{
                    $v->user_id = $user_name->user_name;
                }
            }else{
                $v->user_id = "匿名";
            }
        }
        return $feedback;
    }

    /**
     * 反馈意见删除
     * @param $paramObj
     * @return int
     */
    public function FeedbackDeleteAction($paramObj)
    {
        return $this->mFeedback->delete(['id'=>$paramObj->id]);
    }

    /**
     * 反馈意见ajax返回
     * @return mixed
     * @author fyl
     * @date  2016-07-26
     */
    public function FeedbackAjax()
    {
        return $this->mFeedback->GetFeedbackList();
    }

    /**
    缓存提示
     */
    public function CachePrompt(){
       $order_num = $this->mOrder->Order_Arrearage();
       $new_resource = $this->mNewResource->NewResourceNum();
        $purchase_resource = $this->mPurchaseResource->PurchaseResourceNum();
        $customize = $this->mCustomize->CustomizeNum();
        $count = $order_num+$new_resource+$purchase_resource+$customize;
        $prompt = [
          'order_num' => $order_num,
            'new_resource'=>$new_resource,
            'purchase_resource'=>$purchase_resource,
            'customize'=>$customize,
            'count'=>$count,
        ];
        Cache::forever('cache_prompt', $prompt);
        return 1;
    }

    /**
    缓存ajax
     */
    public function CachePromptAjax(){
        $order_num = $this->mOrder->Order_Arrearage();
        $new_resource = $this->mNewResource->NewResourceNum();
        $purchase_resource = $this->mPurchaseResource->PurchaseResourceNum();
        $customize = $this->mCustomize->CustomizeNum();
        $count = $order_num+$new_resource+$purchase_resource+$customize;
        $prompt = [
            'order_num' => $order_num,
            'new_resource'=>$new_resource,
            'purchase_resource'=>$purchase_resource,
            'customize'=>$customize,
            'count'=>$count,
        ];
        $cache = "<a href='javascript:;' class='dropdown-toggle info-number' data-toggle='dropdown' aria-expanded='false'>
                        <i class='fa fa-envelope-o'></i>
                        <span class='badge bg-green'>
                       ".$prompt['count']."
                        </span>
                    </a>
                    <ul id='menu1' class='dropdown-menu list-unstyled msg_list animated fadeInDown' role='menu'>

                        <li>
                            <div class='text-center'>
                                <a href='/admin/order_list'>
                                        订单
                                    <span style='color: red'>
                                      ".$prompt['order_num']."
                                    </span>
                                </a>
                            </div>
                        </li>
                        <li>
                            <div class='text-center'>
                                <a href='/admin/manage_new_resource'>
                                    现货
                                    <span style='color: red'>
                                     ".$prompt['new_resource']."
                                    </span>
                                </a>
                            </div>
                        </li>
                        <li>
                            <div class='text-center'>
                                <a href='/admin/purchase_resource'>
                                    采购
                                    <span style='color: red'>
                                         ".$prompt['purchase_resource']."
                                    </span>
                                </a>
                            </div>
                        </li>
                        <li>
                            <div class='text-center'>
                                <a href='/admin/customize_list'>
                                    找货助手
                                    <span style='color: red'>
                                        ".$prompt['customize']."
                                    </span>
                                </a>
                            </div>
                        </li>
                    </ul>
        ";
        return $cache;
    }

}